package com.numberone.master.modules.sys.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.numberone.master.common.service.TreeService;
import com.numberone.master.modules.sys.dao.ComplainDao;
import com.numberone.master.modules.sys.entity.Complain;
import com.numberone.master.modules.sys.utils.UserUtils;

@Service
@Transactional(readOnly = true)
public class ComplainService extends TreeService<ComplainDao, Complain> {
	

	public List<Complain> findAll(){
		return UserUtils.getComplainAllList();
	}
	
	public List<Complain> findList(Boolean isAll){
		if (isAll != null && isAll){
			return UserUtils.getComplainAllList();
		}else{
			return UserUtils.getComplainList();
		}
	}
	
	public List<Complain> findListBySkillId(String id){
		return dao.findListBySkillId(id);
	}
	
	@Transactional(readOnly = true)
	public List<Complain> findList(Complain complain){
		if(complain != null){
			complain.setParentIds(complain.getParentIds()+"%");
			return dao.findByParentIdsLike(complain);
		}
		return  new ArrayList<Complain>();
	}
	
	@Transactional(readOnly = false)
	public void save(Complain complain) {
		super.save(complain);
		UserUtils.removeCache(UserUtils.CACHE_COMPLAIN_LIST);
	}
	
	@Transactional(readOnly = false)
	public void delete(Complain complain) {
		super.delete(complain);
		UserUtils.removeCache(UserUtils.CACHE_COMPLAIN_LIST);
	}
	
	/*public Complain get(String id) {
		// TODO Auto-generated method stub
		return null;
	}*/
	
	
	
	

}
